<template>
  <div class="default-main ba-table-box">
    <div class="block">
      <div class="table-block">
        <el-alert class="ba-table-alert"
                  v-if="baTable.table.remark"
                  :title="baTable.table.remark"
                  type="info"
                  show-icon />
        <!-- 表格顶部菜单 -->
        <TableHeader :buttons="['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']"
                     :quick-search-placeholder="t('Quick search placeholder', { fields: '订单号' })">
          <template #shop>
            <el-select filterable
                       v-model="baTable.comSearch.form['shop_id']"
                       clearable>
              <el-option v-for="item in shop_arr"
                         :key="item.shop_id"
                         :label="item.shop_name"
                         :value="item.shop_id">
              </el-option>
            </el-select>
          </template>
          <template #status>
            <el-switch v-model="baTable.comSearch.form['status']" />
          </template>
        </TableHeader>
        <Table></Table>
      </div>
      <!-- 表单 -->
      <PopupForm />
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, provide, onBeforeMount } from 'vue'
import baTableClass from '/@/utils/baTable'
import PopupForm from './popupForm.vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'
import { baTableApi } from '/@/api/common'
import Cookies from 'js-cookie'
import { useI18n } from 'vue-i18n'
import { defaultOptButtons } from '/@/components/table'
import { useAdminInfo } from '/@/stores/adminInfo'
import { getShopList } from '/@/api/backend/common'

defineOptions({
    name: 'advertisement/advaccountlog',
})
const { t } = useI18n()
const adminInfo = useAdminInfo()
const state: {
    buttonLoading: boolean
} = reactive({
    buttonLoading: false
})
const optButtons = defaultOptButtons(['edit', 'delete'])
optButtons[1].display = (row) => {
    return row.id != adminInfo.id
}
const shop_arr = ref([] as any[])
const baTable = new baTableClass(
    new baTableApi('/advertisement/advaccountlog/'),
    {
        column: [
            { type: 'selection', align: 'center', operator: false },
            {
                label: '店铺',
                prop:  'shop_id',
                operator: 'LIKE', 
                comSearchRender:'slot',
                comSearchSlotName: 'shop',
                show: false
            },
            {
                label: '运营',
                prop: 'admin_id',
                align: 'center',
                comSearchRender: 'remoteSelect',
                remote: {
                    pk: 'id',
                    field: 'nickname',
                    remoteUrl: '/advertisement/advaccount/OperationsList',
                    params: { select: true },
                },
                show: false
            },
            {   
                label: 'id', 
                prop: 'id', 
                align: 'center',
                operator: false
            },
            {  
                label: '广告账户', 
                prop: 'advertiser_id', 
                align: 'center',
                operator: '=',
                operatorPlaceholder: '请输入广告账户'
            },
            {   
                label: '店铺', 
                prop: 'shop_name', 
                align: 'center',
                operator: false
            },
            {   
                label: '运营', 
                prop: 'admin_title', 
                align: 'center',
                operator: false
            },
            {
                label: '开始时间', 
                prop: 'createtime', 
                align: 'center',
                operator: false
            },
            {   
                label: '结束时间', 
                prop: 'updatetime', 
                align: 'center',
                operator: false
            },
            {
                label: '状态',
                prop:  'status',
                render: 'tag',
                align: 'center',
                custom: { 'hidden': 'danger', 'normal': 'success' },
                replaceValue:{
                    "hidden": '过期',
                    "normal": '在用',
                },
                comSearchRender:'slot',
                comSearchSlotName: 'status',
                operator: false, 
            },
            {
                label: t('Operate'),
                align: 'center',
                width: '100',
                render: 'buttons',
                buttons: optButtons,
                operator: false,
            }
        ],
        dblClickNotEditColumn: ['all']
    },
    {
        defaultItems: {
            status: '1',
        }
    }
)

provide('baTable', baTable)

baTable.mount()
baTable.getIndex()

const getShopArr = () => {
    getShopList().then(res => {
        if(res.data && res.data.list.length) {
            shop_arr.value = res.data.list
        }
    })
}

onBeforeMount(async () => {
    getShopArr()
})
</script>

<style scoped lang="scss">
</style>
